//	Aviv Charikar	Yael Tzirulnikov	305343600	307955609

package EM;

import java.util.*;
import java.util.Map.Entry;

public class Document {
	private HashMap<String, Integer> wordCounts;
	private int length;
	private String[] topics;
	
	public Document(String line, String[] topics) {
		// Calculate the word counts
		wordCounts = new HashMap<String, Integer>();
		length = 0;
		String[] lineWords = line.split(" ");
		for (String word : lineWords) {
			if (word.length() > 0) {
				Integer count = wordCounts.get(word);
				if (count == null)
					wordCounts.put(word, 1);
				else
					wordCounts.put(word, count + 1);
				length++;
			}
		}
		
		this.topics = topics;
	}
	
	public Set<Entry<String, Integer>> getWordCounts() {
		return wordCounts.entrySet();
	}
	
	public void removeWords(List<String> words) {
		for (String word : words) {
			Integer num = wordCounts.get(word);
			if (num != null) {
				length -= num;
				wordCounts.remove(word);
			}
		}
	}
	
	public double length() {
		return length;
	}
	
	public int getNumAppearances(String word) {
		Integer num = wordCounts.get(word);
		if (num != null)
			return num;
		else
			return 0;
	}
	
	public String[] getTopics() {
		return topics;
	}
}
